package com.zy.openchat.core.model.file;

import android.os.Parcel;
import android.os.Parcelable;

public class FileInfo implements Parcelable {
    public long id;
    public long size;
    //实际大小
    public long expected_size;
    public FileInfoLocal local;
    public FileInfoRemote remote;

    public boolean isCompleted(){
        if(local!=null){
            return local.is_downloading_completed;
        }else {
            return false;
        }
    }

    public long downloadedStart(){
        if (local != null)
            return local.downloaded_prefix_size+local.download_offset;
        return 0;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.id);
        dest.writeLong(this.size);
        dest.writeLong(this.expected_size);
        dest.writeParcelable(this.local, flags);
        dest.writeParcelable(this.remote, flags);
    }

    public FileInfo() {
    }

    protected FileInfo(Parcel in) {
        this.id = in.readLong();
        this.size = in.readLong();
        this.expected_size = in.readLong();
        this.local = in.readParcelable(FileInfoLocal.class.getClassLoader());
        this.remote = in.readParcelable(FileInfoRemote.class.getClassLoader());
    }

    public static final Creator<FileInfo> CREATOR = new Creator<FileInfo>() {
        @Override
        public FileInfo createFromParcel(Parcel source) {
            return new FileInfo(source);
        }

        @Override
        public FileInfo[] newArray(int size) {
            return new FileInfo[size];
        }
    };
}
